<script setup>
import avatar from '@/assets/default.png'
import { Back } from '@element-plus/icons-vue'
import { useUserStore } from '@/stores'
import { useRoute, useRouter } from 'vue-router'
import { computed } from 'vue'
const userStore = useUserStore()
const router = useRouter()

const logout = async () => {
  // 退出操作
  await ElMessageBox.confirm('你确认要进行退出么', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })

  // 清除本地的数据 (token + user信息)
  userStore.removeToken()
  userStore.setUser({})
  router.push('/login')
}
const route = useRoute()
const isNodePath = computed(() => route.path === '/node')
const BackRouter = () => {
  router.back()
}
</script>

<template>
  <el-container class="layout-container">
    <el-header>
      <div
        placement="bottom-end"
        style="
          width: 100%;
          display: flex;
          align-items: center;
          justify-content: space-between;
        "
      >
        <div>
          <el-icon color="white" size="30" v-if="!isNodePath">
            <Back @click="BackRouter()" />
          </el-icon>
        </div>
        <div style="display: flex; align-items: center">
          <span class="el-dropdown__box">
            <el-avatar :src="userStore.user.user_pic || avatar" />
          </span>
          <strong style="margin-left: 10px; color: #fff">
            用户名：{{
              userStore.user.account || userStore.user.account
            }}</strong
          >
          <img
            src="../assets/icons_exit.png"
            style="margin-right: 10px; color: #fff"
            @click="logout"
          />
        </div>
      </div>
    </el-header>
  </el-container>
</template>

<style lang="scss" scoped>
.layout-container {
  // height: 100vh;
  // width: 1920px;
  .el-aside {
    width: 194px;
    color: #fff;
    background-color: #252a48;
    &__logo {
      height: 30px;
      margin-left: 28px;
    }
    .el-menu {
      border-right: none;
    }
  }
  .el-header {
    height: 80px;
    background-color: #252a48;
    background-image: url('../assets/banner.png');
    display: flex;
    align-items: center;
    justify-content: space-between;

    .el-dropdown__box {
      display: flex;
      align-items: center;
      .el-icon {
        color: #999;
        margin-left: 10px;
      }

      &:active,
      &:focus {
        outline: none;
      }
    }
  }
  .el-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #666;
  }
}
</style>
